package com.ddd.controller;

import com.ddd.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class IndexController {

    @GetMapping(value = {"", "/", "index"})
    public String index()
    {
        return "login";
    }

    @PostMapping(value = "login")
    public String main(User user , HttpSession session, Model model){
        if (StringUtils.hasText(user.getUserName()) && StringUtils.hasText(user.getPassword())){
            session.setAttribute("loginUser",user);
        }else {
            model.addAttribute("message", "账号密码错误");
            return "login";
        }
        return "redirect:main.html";
    }

    @GetMapping(value = "main.html")
    public String mainPge(){
        return "main";
    }
}
